package io.fft.flight.common.utils;

import com.alibaba.fastjson2.JSON;

import javax.servlet.http.PushBuilder;
import java.util.List;

/**
 * @Author: likailun
 * @Description: JSON工具类
 * @Date: create in 2024/6/19 22:21
 */
public class J {
    public static String jsonStr(Object obj) {
        if (null == obj) {
            return "";
        }
        if(obj instanceof String){
            return (String) obj;
        }
        return JSON.toJSONString(obj);
    }

    public static <T> T object2Entity(Object obj, Class<T> ct) {
        return JSON.parseObject(jsonStr(obj), ct);
    }

    public static <T> List<T> object2Array(Object obj, Class<T> ct) {
        return JSON.parseArray(jsonStr(obj), ct);
    }
}
